<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript"
	src="js/jquery-easyui-1.5.4.2/jquery.min.js"></script>
<script type="text/javascript"
	src="js/jquery-easyui-1.5.4.2/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript"
	src="js/jquery-easyui-1.5.4.2/jquery.easyui.min.js"></script>
<link rel="stylesheet" type="text/css"
	href="js/jquery-easyui-1.5.4.2/themes/icon.css" />
<link rel="stylesheet" type="text/css"
	href="js/jquery-easyui-1.5.4.2/themes/black/easyui.css" />
<script type="text/javascript" src="js/common.js"></script>
<title>添加订单，订单明细</title>
</head>
<body>
<style type="text/css">
.step {
	margin-top: 20px;
}
</style>
	<script type="text/javascript">
		$(function() {
			$("#zj-win-emp-add-row").linkbutton({
				onClick:function(){
					$("#zj-co-od-zj-dia").dialog('open');
				}
			});
			
			$("#zj-win-order-co-remove-rows").linkbutton({onClick:function(){
				alert("aa")
				var dg = $("#zj-layout-co-od-batch-add-tabs-dg");
				var rows = dg.datagrid("getSelections");
				for(var i = rows.length - 1; i >= 0; i --){
					var index = dg.datagrid("getRowIndex", rows[i]);
					dg.datagrid("deleteRow", index);
				}
			}});
			
			$("#zj-layout-co-od-batch-add-cancel").linkbutton({
				onClick:function(){
					$("#zj-co-od-zj-dialog").window("close");
				}
			})
			
			$("#zj-layout-co-od-batch-add-save").linkbutton({
				onClick:function(){
					
					$("<form method='post'>").appendTo(document.body).form({
						url:"addCood",
						onSubmit:function(params){
							//获取订单信息
						var coTheme = $("#coTheme").textbox("getValue");
						var coCusId = $("#coCusId").textbox("getValue");
						alert(coCusId)
						var coCusName = $("#coCusName").textbox("getValue");
						var coPayWay = $("#coPayWay").textbox("getValue");
						var coType = $("#coType").textbox("getValue");
						var coAllMoney = $("#coAllMoney").textbox("getValue");
						var coStartTime = $("#coStartTime").textbox("getValue");
						var coEndTime = $("#coEndTime").textbox("getValue");
						var coSendTime = $("#coSendTime").textbox("getValue");
						var coRemarks = $("#coRemarks").textbox("getValue");
						var coText = $("#coText").textbox("getValue");
						var coState = $('input[name="coState"]:checked').val();
						alert(coState)
						var coOwner = $("#coOwner").textbox("getValue");
						var coGetMan = $("#coGetMan").textbox("getValue");
						var coManPhone = $("#coManPhone").textbox("getValue");
						var coManAddress = $("#coManAddress").textbox("getValue");
							//获取明细
						var dg = $("#zj-layout-co-od-batch-add-tabs-dg");
						var clist = dg.datagrid("getRows");
						//作为请求参数
						params['cOrder.coTheme'] = coTheme;
						params['cOrder.coCusId'] = coCusId;
						params['cOrder.coCusName'] = coCusName;
						params['cOrder.coPayWay'] = coPayWay;
						params['cOrder.coType'] = coType;
						params['cOrder.coAllMoney'] = coAllMoney;
						params['cOrder.coStartTime'] = coStartTime;
						params['cOrder.coEndTime'] = coEndTime;
						params['cOrder.coSendTime'] = coSendTime;
						params['cOrder.coRemarks'] = coRemarks;
						params['cOrder.coText'] = coText;
						params['cOrder.coState'] = coState;
						params['cOrder.coOwner'] = coOwner;
						params['cOrder.coGetMan'] = coGetMan;
						params['cOrder.coManPhone'] = coManPhone;
						params['cOrder.coManAddress'] = coManAddress;
						for(var i = 0; i < clist.length; i ++){
							//params['cList[' + i +'].empno'] = emps[i].empno;
							params['orderdetails1s[' + i +'].odProName'] = clist[i].odProName;
							params['orderdetails1s[' + i +'].odProType'] = clist[i].odProType;
							params['orderdetails1s[' + i +'].odPrice'] = clist[i].odPrice;
							params['orderdetails1s[' + i +'].odNumber'] = clist[i].odNumber;
							params['orderdetails1s[' + i +'].odPlanTime'] = clist[i].odPlanTime;
							params['orderdetails1s[' + i +'].odOwner'] = clist[i].odOwner;
							params['orderdetails1s[' + i +'].odRemarks'] = clist[i].odRemarks;
						}
						return $(this).form('validate');
						},
						success:function(v){
							//$.messager.alert("提示", "保存成功！");
							$("#coTheme").textbox("clear");
							$("#coCusId").textbox("clear");
							$("#coCusName").textbox("clear");
							$("#coPayWay").textbox("clear");
							$("#coType").textbox("clear");
							$("#coAllMoney").textbox("clear");
							$("#coStartTime").textbox("clear");
							$("#coEndTime").textbox("clear");
							$("#coSendTime").textbox("clear");
							$("#coRemarks").textbox("clear");
							$("#coText").textbox("clear");
							$("#coState").textbox("clear");
							$("#coOwner").textbox("clear");
							$("#coGetMan").textbox("clear");
							$("#coManPhone").textbox("clear");
							$("#coManAddress").textbox("clear");
							var dg = $("#zj-layout-co-od-batch-add-tabs-dg");
							var rows = dg.datagrid("getRows");
							for(var i = rows.length - 1; i >= 0; i --){
								var index = dg.datagrid("getRowIndex", rows[i]);
								dg.datagrid("deleteRow", index);
							}	
							$('#zj-co-od-zj-dialog').dialog('close');
							$("#zj-order-dg").datagrid('reload');
						}
					}).submit();
				}
			});
		});
	</script>
	
	<div id="zj-co-od-zj-dia" class="easyui-dialog" style="width: 400px; height: 440px;"
		data-options="href:'toOdf2',iconCls:'icon-save',title:'添加明细',resizable:true,closed:true,modal:true,
			buttons:[{
				text:'保存',
				iconCls:'icon-ok',
				handler:function(){
				var proName = $('#zj-txt-pro').textbox('getValue');
				var odProType = $('#zj-txt-proType').combobox('getValue');
				var odPrice = $('#zj-txt-odPrice').textbox('getValue');
				var odNumber = $('#zj-txt-odNumber').numberbox('getValue');
				var odPlanTime = $('#zj-txt-odPlanTime').textbox('getValue');
				var odOwner = $('#zj-txt-odOwner').textbox('getValue');
				var odRemarks = $('#zj-txt-odRemarks').combobox('getValue');
				
				var obj = {
						odRemarks:odRemarks,
						odProName:proName,
						odProType: odProType,
						odPrice: odPrice,
						odNumber:odNumber,
						odPlanTime:odPlanTime,
						odOwner:odOwner
				};
				$('#zj-layout-co-od-batch-add-tabs-dg').datagrid('appendRow', obj);
				$('#zj-co-od-zj-dia').window('close');	
				$('#zj-txt-pro').combobox('clear');
				$('#zj-txt-proType').textbox('clear');
				$('#zj-txt-odPrice').numberbox('clear');
				$('#zj-txt-odNumber').numberbox('clear');
				$('#zj-txt-odPlanTime').textbox('clear');
				$('#zj-txt-odOwner').textbox('clear');
				$('zj-txt-odRemarks').textbox('clear');
				}
			},{
				text:'关闭',
				iconCls:'icon-cancel',
				handler:function(){
				$('#zj-co-od-zj-dia').window('close');
				}
			}]"></div>
		
	<div id="zj-co-od-add" class="easyui-layout"
		data-options="fit:true,border:false"
		style="width: 600px; height: 400px;">
		<div data-options="region:'north',border:false" style="height: 260px;">
			<fieldset style="border-radius: 5px; border: 1px solid gray;">
				<legend>合同订单信息</legend>
				<table width="100%" id="zj-co-co-table" style="border-collapse:separate; border-spacing:0px 10px;">
					<tr>
						<td>
							<input id="coTheme" class="easyui-textbox"
							data-options="required:true,labelAlign:'right',label:'主题',
					width:220, labelWidth:60"
							name="coTheme">
							<input id="coCusId" name="coCusId" type="hidden" class="easyui-textbox">
						</td>
						<td>
						<input id="coCusName" name="coCusName"
							class="easyui-textbox"
							data-options="editable:false,buttonText:'选择客户',label:' ',labelWidth:'60', width: 300, 
					onClickButton:function(){
						getCustomer(function(row){
							$('#coCusName').textbox('setValue', row.custName);
							$('#coCusName').textbox('setText', row.custName);
							$('#coCusId').textbox('setValue',row.custId);
						});
					}">
						</td>
						<td>
							<select id="coPayWay" class="easyui-combobox"
							data-options="editable:false,panelHeight:'auto',labelAlign:'right',required:true,label:'付款方式',
					width:280, labelWidth:62"
							name="coPayWay">
							<option disabled selected value=''></option>
							<option value="支票">支票</option>
							<option value="现金">现金</option>
							<option value="邮政汇款">邮政汇款</option>
							<option value="网上银行">网上银行</option>
						</select>
						</td>
					</tr>
					
					<tr>
						<td>
							<select id="coType" name="coType" class="easyui-combobox"
							data-options="editable:false,panelHeight:'auto',labelAlign:'right',required:false,label:'分类',
					width:250, labelWidth:60"
							name="coType">
							<option disabled selected value=''></option>
							<option value="产品销售">产品销售</option>
							<option value="服务">服务</option>
							<option value="业务合作">业务合作</option>
							<option value="代理分销">代理分销</option>
							<option value="其他">其他</option>
						</select>
						</td>
						<td>
							<input id="coAllMoney" class="easyui-numberbox" name="coAllMoney"
							data-options="min:0,precision:2,labelAlign:'right',required:true,label:'总金额',
					width:200, labelWidth:60">
						</td>
						<td>
							<input id="coStartTime" class="easyui-datebox"
							data-options="required:true,labelAlign:'right',label:'签约日期',
					width:300, labelWidth:62"
							name="coStartTime">
						</td>
					</tr>
					
					<tr>
						<td>
							<input id="coEndTime" class="easyui-datebox"
							data-options="required:true,labelAlign:'right',label:'结束日期',
					width:280, labelWidth:62"
							name="coEndTime">
						</td>
						<td>
							<input id="coSendTime" class="easyui-datebox"
							data-options="required:true,labelAlign:'right',label:'发货时间',
					width:280, labelWidth:62"
							name="coSendTime">
						</td>
						<td>
							<input id="coRemarks" class="easyui-textbox"
							data-options="multiline:true,required:false,labelAlign:'right',label:'备注',
					width:320,height:35,labelWidth:60"
							name="coRemarks">
						</td>
					</tr>
					
					<tr>
						<td>
							<input id="coText" class="easyui-textbox"
							data-options="multiline:true,labelAlign:'right',required:false,label:'正文',
					width:340,height:40,labelWidth:60"
							name="coText">
						</td>
						<td>
							状态<input  value="执行中" name="coState"
							 type="radio">执行中<input value="结束"
							name="coState" type="radio">结束
						</td>
						<td>
							<input id="coOwner" name="coOwner" class="easyui-textbox"
							data-options="editable:false,buttonText:'所有者', label:' ', labelWidth:'60', width: 300, 
					onClickButton:function(){
						getCustomer(function(row){
							$('#coOwner').textbox('setValue', row.custName);
						});
					}">
						</td>
					</tr>
					
					<tr>
						<td>
							<input id="coGetMan" class="easyui-textbox"
							data-options="required:false,labelAlign:'right',label:'收货人',
					width:200, labelWidth:60"
							name="coGetMan">
						</td>
						<td>
							<input id="coManPhone" class="easyui-textbox"
							data-options="required:false,labelAlign:'right',validType:'mobile',label:'电话',
					width:300, labelWidth:60"
							name="coManPhone">
						</td>
						<td>
							<input id="coManAddress" class="easyui-textbox"
							data-options="required:false,labelAlign:'right',label:'地址',
					width:350, labelWidth:60"
							name="coManAddress">
						</td>
					</tr>
				</table>
			</fieldset>
		</div>



		<div data-options="region:'center',border:false"
			style="padding: 5px; background: #eee;">
			<div id="zj-layout-co-od-batch-add-tabs-tbs" class="easyui-tabs"
				data-options='fit:true,border:false'>
				<div title="订单明细">
					<table id="zj-layout-co-od-batch-add-tabs-dg"
						class="easyui-datagrid"
						data-options="toolbar:'#zj-layout-co-od-batch-add-tabs-tb',fit:true,fitColumns:true,border:false,
			    		columns:[[    
				       <!--  {field:'odId',title:'编号',width:1}, -->
				       <!--  {field:'proId',title:'产品编号',width:1}, -->
				        {field:'odProName',title:'产品',width:2},
				        {field:'odProType',title:'产品类别',width:2},
				        {field:'odRemarks',title:'产品单位',width:1},
				        {field:'odPrice',title:'单价',width:1},
				        {field:'odNumber',title:'订单数量',width:1},
				        {field:'odPlanTime',title:'交付日期',width:1},
				        {field:'odOwner',title:'所有者',width:1}  
				    	]]"></table>
					<div id="zj-layout-co-od-batch-add-tabs-tb">
						<a id="zj-win-emp-add-row" href="#" class="easyui-linkbutton"
							data-options="iconCls:'icon-add',plain:true">添加一行</a> <a
							id="zj-win-order-co-remove-rows" href="#" class="easyui-linkbutton"
							data-options="iconCls:'icon-cut',plain:true">删除行</a>
					</div>
				</div>
			</div>
		</div>
		
		<div data-options="region:'south',border:false" style="height:35px;padding:5px;">
	    	<a id="zj-layout-co-od-batch-add-save" class="easyui-linkbutton" data-options="iconCls:'icon-ok'">保存</a>
	    	<a id="zj-layout-co-od-batch-add-cancel" class="easyui-linkbutton" data-options="iconCls:'icon-cancel'">取消</a>
	    </div>	
	</div>

</body>
</html>